<?php

/**
 * 订单分析
 *
 * @author haifeng.wu
 */

require_once 'CommonController.php';
class Admin_AnalyticsFeedbackController extends Admin_CommonController
{
    /**
     * 初始化函数
     * 
     * @return void
     */
    public function init()
    {
        parent::init();
        $this->_model = new Application_Model_DayData();
        $this->partnerProductModel = new Application_Model_PartnerProduct();
        $this->feedbackModel = new Application_Model_DaydataFeedback();
        $this->view->title = "管理中心";
    }

    /**
     * 默认动作
     * 
     * @return void
     */
    public function listAction()
    {
        $vars = array();
        $wheres = array();
        $vars['osname'] = $this->_request->getPost('osname');
        $vars['startTime'] = trim($this->_request->getPost('startTime'));
        $productCode = Application_Model_UserLogin::getInstance()->getUserCurrentProductCode();
        $memorysql = "SELECT * FROM mob_product_order WHERE `productCode`='{$productCode}' AND `countDate`='{$vars['startTime']}'";
        $memoryarrtmp = $this->_model->getAdapter()->fetchAll($memorysql);
        $memoryarr = array();
        foreach ($memoryarrtmp as $item) {
            $memoryarr[$item['osName']] = $item;
        }
        if ($this->_request->isPost()) {
            $wheres = array();
            if(empty($vars['startTime'])){
                echo $this->view->message('请正确填写。') ;
                exit;
            }
            $vars['productName'] = $this->partnerProductModel->getProductNameByProductCode($productCode);
            $checknext = $this->feedbackModel->filterData(array('productCode' => $productCode, 'date' => $vars['startTime']));
//            if (!empty($checknext)) {
//                $arrSerialize = unserialize($checknext['serializeData']);
//                foreach ($memoryarr as $key => $val) {
//                    $arrSerialize['arrone'][$key][2]['0'] = empty($arrSerialize['arrone'][$key][2]['hiddenval']) ? '-' : round($val['orderAmount']/$arrSerialize['arrone'][$key][2]['hiddenval'], 2);
//                    $arrSerialize['arrone'][$key][2]['b2'] = $val['orderAmount'];
//                }
//                $this->view->arrone = $arrSerialize['arrone'];
//                $this->view->arrtwo = $arrSerialize['arrtwo'];
//                $this->view->arrthree = $arrSerialize['arrthree'];
//                $this->view->arrSerialize = serialize(array('arrone'=>$arrSerialize['arrone'],'arrtwo'=>$arrSerialize['arrtwo'],'arrthree'=>$arrSerialize['arrthree']));
//            } else {
                $sql = "SELECT productCode,sourceId,sourceSubId,osName,SUM(bootNum) as bootNum,SUM(installOkOrderNum) as installOkOrderNum,
                        SUM(bootClientNum) as bootClientNum,SUM(installOrderNum) as installOrderNum,SUM(okOrderNum) as okOrderNum,SUM(installNum) as installNum,SUM(okOrderAmount) as okOrderAmount,
                        SUM(price) as price FROM (
                            SELECT a.productCode,a.sourceId,a.sourceSubId,a.osName,a.bootNum,a.installOkOrderNum,a.bootClientNum,a.installOrderNum,a.okOrderNum,a.installNum,a.okOrderAmount,b.price
                            FROM (
                                SELECT productCode,sourceId,sourceSubId,`date`,osName,SUM(bootNum) as bootNum,SUM(installOkOrderNum) as installOkOrderNum,
                                       SUM(bootClientNum) as bootClientNum,SUM(installOrderNum) as installOrderNum,SUM(okOrderNum) as okOrderNum,SUM(installNum) as installNum,SUM(okOrderAmount) as okOrderAmount 
                                FROM mob_day_data 
                                WHERE `productCode`='{$productCode}' AND `date`='{$vars['startTime']}' AND osName in ('iphone','android','symbian','windowsphone')
                                GROUP BY sourceId,sourceSubId    
                            ) AS a
                            LEFT JOIN (
                            SELECT productCode,sourceId,sourceSubId,`date`,SUM(price) as price FROM mob_source_schedual WHERE `productCode`='{$productCode}' AND `date`='{$vars['startTime']}' GROUP BY sourceId,sourceSubId 
                            ) AS b ON a.productCode = b.productCode AND a.sourceId = b.sourceId AND a.sourceSubId = b.sourceSubId        
                        )c GROUP BY osName,sourceId,sourceSubId
                ";
                $rowTm = $this->_model->getAdapter()->fetchAll($sql);
                foreach ($rowTm as $k => $v) {
                    $rowTm[$k]['osName'] = strtolower($v['osName']);
                }
                $osNaversion = array('iphone','android','symbian','windowsphone');
                $rows = array();
                foreach($rowTm as $item){
                    foreach($osNaversion as $ka){
                        if($item['osName'] == $ka){
                            $rows[$ka]['productCode'] = $item['productCode'];
                            $rows[$ka]['osName'] = $item['osName'];
                            $rows[$ka]['bootNum'] = isset($rows[$ka]['bootNum']) ? $rows[$ka]['bootNum']+$item['bootNum'] : $item['bootNum'];
                            $rows[$ka]['installOkOrderNum'] = isset($rows[$ka]['installOkOrderNum']) ? $rows[$ka]['installOkOrderNum']+$item['installOkOrderNum'] : $item['installOkOrderNum'];
                            $rows[$ka]['bootClientNum'] = isset($rows[$ka]['bootClientNum']) ? $rows[$ka]['bootClientNum']+$item['bootClientNum'] : $item['bootClientNum'];
                            $rows[$ka]['installOrderNum'] = isset($rows[$ka]['installOrderNum']) ? $rows[$ka]['installOrderNum']+$item['installOrderNum'] : $item['installOrderNum'];
                            $rows[$ka]['okOrderNum'] = isset($rows[$ka]['okOrderNum']) ? $rows[$ka]['okOrderNum']+$item['okOrderNum'] : $item['okOrderNum'];
                            $rows[$ka]['installNum'] = isset($rows[$ka]['installNum']) ? $rows[$ka]['installNum']+$item['installNum'] : $item['installNum'];
                            $rows[$ka]['okOrderAmount'] = isset($rows[$ka]['okOrderAmount']) ? $rows[$ka]['okOrderAmount']+$item['okOrderAmount'] : $item['okOrderAmount'];
                            $rows[$ka]['price'] = isset($rows[$ka]['price']) ? $rows[$ka]['price']+$item['price'] : $item['price'];
                        }
                    }
                }
                $arrone = array();
                $arrCou = array('yekokOrderNum'=>0, 'yekokOrderAmount'=>0, 'bootNum'=>0,'installOkOrderNum'=>0,'bootClientNum'=>0,'installOrderNum'=>0,'okOrderNum'=>0,'installNum'=>0,'okOrderAmount'=>0,'price'=>0);
                foreach($rows as $item){
                    $arrone[$item['osName']][0][0] = $item['okOrderNum'];
                    $arrone[$item['osName']][1][0] = $item['installNum'];
//                    $arrone[$item['osName']][2][0] = empty($item['price']) ? '-': round($item['okOrderAmount']/$item['price'], 2);
                    //$arrone[$item['osName']][2]['b2'] = (!isset($memoryarr[$item['osName']]['orderAmount']) || empty($item['price']) || $item['price']==0) ? '-': round($memoryarr[$item['osName']]['orderAmount']/$item['price'], 2);
//                    $arrone[$item['osName']][2][0] = '-';
                    $arrone[$item['osName']][3][0] = empty($item['installNum']) ? '-': round(($item['okOrderNum']/$item['installNum'])*100, 2);
                    $arrone[$item['osName']][3]['b3'] = (!isset($memoryarr[$item['osName']]['orderNum']) || empty($item['installNum']) || $item['installNum']==0) ? '-': round(($memoryarr[$item['osName']]['orderNum']/$item['installNum'])*100, 2);
                    $arrone[$item['osName']][4][0] = empty($item['bootClientNum']) ? '-': round(($item['okOrderNum']/$item['bootClientNum'])*100, 2);
                    $arrone[$item['osName']][4]['b4'] = (!isset($memoryarr[$item['osName']]['orderNum']) || empty($item['bootClientNum']) || $item['bootClientNum']==0) ? '-': round(($memoryarr[$item['osName']]['orderNum']/$item['bootClientNum'])*100, 2);
                    $arrone[$item['osName']][2]['hiddenval'] = $item['price'];
                    $arrCou['bootNum'] += $item['bootNum'];
                    $arrCou['installOkOrderNum'] += $item['installOkOrderNum'];
                    $arrCou['bootClientNum'] += $item['bootClientNum'];
                    $arrCou['installOrderNum'] += $item['installOrderNum'];
                    $arrCou['okOrderNum'] = isset($memoryarr[$item['osName']]['orderNum']) ? ($arrCou['okOrderNum']+$memoryarr[$item['osName']]['orderNum']) : $arrCou['okOrderNum'];
                    $arrCou['yekokOrderNum'] += $item['okOrderNum'];
                    $arrCou['installNum'] += $item['installNum'];
                    $arrCou['okOrderAmount'] = isset($memoryarr[$item['osName']]['orderAmount']) ? ($arrCou['okOrderAmount']+$memoryarr[$item['osName']]['orderAmount']) : $arrCou['okOrderAmount'];
                    $arrCou['yekokOrderAmount'] += $item['okOrderAmount'];
                    $arrCou['price'] += $item['price'];
                }
                
                if (empty($arrone)) {
                    exit($this->view->message('无数据'));
                }
                foreach ($memoryarr as $key => $val) {
                    $arrone[$key][0]['b0'] = $val['orderNum'];
                    //$arrone[$key][2]['b2'] = $val['orderAmount'];
                }

                $arrthree = array();
                $arrthree[0][0] = $arrCou['installNum'];
                $arrthree[1][0] = 0;
                $arrthree[2][0] = 0;
                $arrthree[4][0] = 0;
                $arrthree[5][0] = 0;
                $haveSouAmount = 0;
                $haveSouOkOrderNum = 0;
                $haveSouInstallNum = 0;
                $sqlOo = "SELECT b.`code`,a.sourceId,a.sourceSubid FROM mob_source as a LEFT JOIN  mob_member as b ON a.memberCode = b.`code` WHERE `name`='苹果官方市场' GROUP BY a.sourceId,a.sourceSubId";
                $rowOo = $this->_model->getAdapter()->fetchAll($sqlOo);
                $arrthree[7][0] = 0;
                $appleInstallNum = 0;
                $sourOsnameAmount = array('iphone' => 0,'android' => 0,'symbian' => 0,'windowsphone' => 0);
                foreach ($rowTm as $item) {
                    if (!empty($item['price'])) {
                        $sourOsnameAmount[$item['osName']] += $item['okOrderAmount'];
                        $haveSouOkOrderNum += $item['okOrderNum'];
                        $haveSouInstallNum += $item['installNum'];
                        $arrthree[1][0] += $item['installNum'];
                        $haveSouAmount += $item['okOrderAmount'];
                        if($item['osName'] == 'iphone'){
                            $arrthree[4][0] += $item['okOrderNum'];
                        }
                        if($item['osName'] == 'android'){
                            $arrthree[5][0] += $item['okOrderNum'];
                        }
                    } else {
                        $arrthree[2][0] += $item['installNum'];
                    }
                    foreach ($rowOo as $ids) {
                        if ($ids['sourceId'] == $item['sourceId'] && $ids['sourceSubid'] == $item['sourceSubId']) {
                            $arrthree[7][0] += $item['okOrderNum'];
                            $appleInstallNum += $item['installNum'];
                        }
                    }
                }
                $arrthree[3][0] = $appleInstallNum;
                $arrthree[6][0] = empty($haveSouInstallNum) ? '-' : round(($haveSouOkOrderNum/$haveSouInstallNum)*100, 2);
                $arrthree[8][0] = empty($appleInstallNum) ? '-' : round($arrthree[7][0]/$appleInstallNum, 2);
                $this->view->arrthree = $arrthree;
                $arrtwo = array();
                $arrtwo[0][0] = empty($arrCou['installNum']) ? '-' : round(($arrCou['installOkOrderNum']/$arrCou['installNum'])*100, 2);
                $arrtwo[1][0] = empty($arrCou['yekokOrderNum']) ? '-' : round($arrCou['yekokOrderAmount']/$arrCou['yekokOrderNum'], 2);
                $arrtwo[1][1] = empty($arrCou['okOrderNum']) ? '-' : round($arrCou['okOrderAmount']/$arrCou['okOrderNum'], 2);
                $arrtwo[2][0] = empty($arrCou['installNum']) ? '-' : round(($arrCou['yekokOrderNum']/$arrCou['installNum'])*100, 2);
                $arrtwo[2][1] = empty($arrCou['installNum']) ? '-' : round(($arrCou['okOrderNum']/$arrCou['installNum'])*100, 2);
                $arrtwo[3][0] = $arrCou['bootNum'];
                $arrtwo[4][0] = empty($arrCou['bootClientNum']) ? '-' : round($arrCou['bootNum']/$arrCou['bootClientNum'], 2);
                $arrtwo[5][0] = empty($arrCou['price']) ? '-' : round($haveSouAmount/$arrCou['price'], 2);
                //$arrtwo[5][1] = empty($arrCou['price']) ? '-' : round($arrCou['okOrderAmount']/$arrCou['price'], 2);
                $arrtwo[5]['hiddenval'] = $arrCou['price'];
                $arrtwo[6][0] = $arrCou['yekokOrderNum'];
                $arrtwo[6][1] = $arrCou['okOrderNum'];
                $arrtwo[7][0] = empty($arrCou['bootClientNum']) ? '-' : round(($arrCou['yekokOrderNum']/$arrCou['bootClientNum'])*100, 2);
                $arrtwo[7][1] = empty($arrCou['bootClientNum']) ? '-' : round(($arrCou['okOrderNum']/$arrCou['bootClientNum'])*100, 2);
                foreach ($rows as $item) {
                    $arrone[$item['osName']][2][0] = empty($item['price']) ? '-': round($sourOsnameAmount[$item['osName']]/$item['price'], 2);
                }
                $this->view->arrone = $arrone;
                $this->view->arroneRow = $rows;
                $this->view->arrtwo = $arrtwo;
                $this->view->arrtwoarrCou = $arrCou;
                $this->view->arrSerialize = $arrSerialize = serialize(array('arrone'=>$arrone,'arrtwo'=>$arrtwo,'arrthree'=>$arrthree));
//            }
            $this->view->vars = $vars;
            $this->renderScript('analytics-feedback/report.php');
        }
        $this->view->vars = $vars;
    }
    
    
    public function excelAction()
    {
        if ($this->_request->isPost()) {
            $arrserialize = unserialize($this->_request->getPost('arrserialize'));
            $roiarr = $this->_request->getPost('roiarr');
            foreach ($roiarr as $item) {
                $exp = explode('||||',$item);
                if($exp[0] == 'arrone'){
                    if (isset($arrserialize[$exp[0]][$exp[1]][2][0])) {
                        $arrserialize[$exp[0]][$exp[1]][2][0] = $exp[2];
                    }
                }
                if($exp[0] == 'arrtwo'){
                    if (isset($arrserialize[$exp[0]][5][0])) {
                        $arrserialize[$exp[0]][5][0] = $exp[1];
                    }
                }
            }
            $inputarrone = $this->_request->getPost('inputarrone');
            $acceptone = $this->_request->getPost('acceptone');
            $accepttwo = $this->_request->getPost('accepttwo');
            $hname = $this->_request->getPost('hname');
            foreach ($inputarrone as $key => $val) {
                if (is_numeric($val)) {
                    $inputarrone[$key] = $val*1.0;
                } else {
                    $inputarrone[$key] = NULL;
                }
            }
            foreach ($acceptone as $key => $val) {
                if (is_numeric($val)) {
                    $acceptone[$key] = $val*1.0;
                } else {
                    $acceptone[$key] = NULL;
                }
            }
            foreach ($accepttwo as $key => $val) {
                if (is_numeric($val)) {
                    $accepttwo[$key] = $val*1.0;
                } else {
                    $accepttwo[$key] = NULL;
                }
            }
            $i = 0;
            foreach ($arrserialize['arrone'] as $key => $val) {
                $arrserialize['arrone'][$key][0]['name0'] = $hname[$i];
                $arrserialize['arrone'][$key][1]['name1'] = $hname[$i+1];
                $arrserialize['arrone'][$key][2]['name2'] = $hname[$i+2];
                $arrserialize['arrone'][$key][3]['name3'] = $hname[$i+3];
                $arrserialize['arrone'][$key][4]['name4'] = $hname[$i+4];
                
                $arrserialize['arrone'][$key][0]['b0'] = $inputarrone[$i];
                $arrserialize['arrone'][$key][1]['b1'] = $inputarrone[$i+1];
                $arrserialize['arrone'][$key][2]['b2'] = $inputarrone[$i+2];
                $arrserialize['arrone'][$key][3]['b3'] = $inputarrone[$i+3];
                $arrserialize['arrone'][$key][4]['b4'] = $inputarrone[$i+4];
                
                $arrserialize['arrone'][$key][0]['gap0'] = ($inputarrone[$i] === NULL) ? '-' : $inputarrone[$i] - $val[0][0];
                $arrserialize['arrone'][$key][1]['gap1'] = ($inputarrone[$i+1] === NULL) ? '-' : $inputarrone[$i+1] - $val[1][0];
                //$arrserialize['arrone'][$key][2]['gap2'] = ($inputarrone[$i+2] === NULL) ? '-' : $inputarrone[$i+2] - $val[2][0];
                $arrserialize['arrone'][$key][2]['gap2'] = '-';
                $arrserialize['arrone'][$key][3]['gap3'] = ($inputarrone[$i+3] === NULL) ? '-' : $inputarrone[$i+3] - $val[3][0];
                $arrserialize['arrone'][$key][4]['gap4'] = ($inputarrone[$i+4] === NULL) ? '-' : $inputarrone[$i+4] - $val[4][0];
                
                $arrserialize['arrone'][$key][0]['acceptone0'] = $acceptone[$i];
                $arrserialize['arrone'][$key][1]['acceptone1'] = $acceptone[$i+1];
                $arrserialize['arrone'][$key][2]['acceptone2'] = $acceptone[$i+2];
                $arrserialize['arrone'][$key][3]['acceptone3'] = $acceptone[$i+3];
                $arrserialize['arrone'][$key][4]['acceptone4'] = $acceptone[$i+4];
                
                $arrserialize['arrone'][$key][0]['accepttwo0'] = $accepttwo[$i];
                $arrserialize['arrone'][$key][1]['accepttwo1'] = $accepttwo[$i+1];
                $arrserialize['arrone'][$key][2]['accepttwo2'] = $accepttwo[$i+2];
                $arrserialize['arrone'][$key][3]['accepttwo3'] = $accepttwo[$i+3];
                $arrserialize['arrone'][$key][4]['accepttwo4'] = $accepttwo[$i+4];

                $arrserialize['arrone'][$key][0]['is0'] = ($arrserialize['arrone'][$key][0]['gap0'] === '-') ? '-' : ((abs($arrserialize['arrone'][$key][0]['gap0'])>=$acceptone[$i] && abs($arrserialize['arrone'][$key][0]['gap0'])<=$accepttwo[$i]) ? 'Y' : 'N');
                $arrserialize['arrone'][$key][1]['is1'] = ($arrserialize['arrone'][$key][1]['gap1'] === '-') ? '-' : ((abs($arrserialize['arrone'][$key][1]['gap1'])>=$acceptone[$i+1] && abs($arrserialize['arrone'][$key][1]['gap1'])<=$accepttwo[$i+1]) ? 'Y' : 'N');
                //$arrserialize['arrone'][$key][2]['is2'] = ($arrserialize['arrone'][$key][2]['gap2'] === '-') ? '-' : ((abs($arrserialize['arrone'][$key][2]['gap2'])>=$acceptone[$i+2] && abs($arrserialize['arrone'][$key][2]['gap2'])<=$accepttwo[$i+2]) ? 'Y' : 'N');
                $arrserialize['arrone'][$key][2]['is2'] = '-';
                $arrserialize['arrone'][$key][3]['is3'] = ($arrserialize['arrone'][$key][3]['gap3'] === '-') ? '-' : ((abs($arrserialize['arrone'][$key][3]['gap3'])>=$acceptone[$i+3] && abs($arrserialize['arrone'][$key][3]['gap3'])<=$accepttwo[$i+3]) ? 'Y' : 'N');
                $arrserialize['arrone'][$key][4]['is4'] = ($arrserialize['arrone'][$key][4]['gap4'] === '-') ? '-' : ((abs($arrserialize['arrone'][$key][4]['gap4'])>=$acceptone[$i+4] && abs($arrserialize['arrone'][$key][4]['gap4'])<=$accepttwo[$i+4]) ? 'Y' : 'N');
                
                $i += 5;
            }
            $inputarrtwo = $this->_request->getPost('inputarrtwo');
            $accepttwoone = $this->_request->getPost('accepttwoone');
            $accepttwotwo = $this->_request->getPost('accepttwotwo');
            $htwoname = $this->_request->getPost('htwoname');
            foreach ($inputarrtwo as $key => $val) {
                if (is_numeric($val)) {
                    $inputarrtwo[$key] = $val*1.0;
                } else {
                    $inputarrtwo[$key] = NULL;
                }
            }
            foreach ($accepttwoone as $key => $val) {
                if (is_numeric($val)) {
                    $accepttwoone[$key] = $val*1.0;
                } else {
                    $accepttwoone[$key] = NULL;
                }
            }
            foreach ($accepttwotwo as $key => $val) {
                if (is_numeric($val)) {
                    $accepttwotwo[$key] = $val*1.0;
                } else {
                    $accepttwotwo[$key] = NULL;
                }
            }
            foreach ($arrserialize['arrtwo'] as $key => $val) {
                $arrserialize['arrtwo'][$key][1] = $inputarrtwo[$key];
                $arrserialize['arrtwo'][$key][2] = ($inputarrtwo[$key] === NULL) ? '-' : ($inputarrtwo[$key] - $val[0]);
                $arrserialize['arrtwo'][$key][3] = $accepttwoone[$key];
                $arrserialize['arrtwo'][$key][4] = $accepttwotwo[$key];
                $arrserialize['arrtwo'][$key][5] = ($arrserialize['arrtwo'][$key][2] === '-') ? '-' : ((abs($arrserialize['arrtwo'][$key][2])>=$arrserialize['arrtwo'][$key][3] && abs($arrserialize['arrtwo'][$key][2])<=$arrserialize['arrtwo'][$key][4]) ? 'Y' : 'N');
                $arrserialize['arrtwo'][$key][6] = $htwoname[$key];
                if ($key == 5) {
                    $arrserialize['arrtwo'][$key][2] = '-';
                    $arrserialize['arrtwo'][$key][5] = '-';
                }
            }
            $inputarrthree = $this->_request->getPost('inputarrthree');
            $acceptthreeone = $this->_request->getPost('acceptthreeone');
            $acceptthreetwo = $this->_request->getPost('acceptthreetwo');
            $hthreename = $this->_request->getPost('hthreename');
            foreach ($inputarrthree as $key => $val) {
                if (is_numeric($val)) {
                    $inputarrthree[$key] = $val*1.0;
                } else {
                    $inputarrthree[$key] = NULL;
                }
            }
            foreach ($acceptthreeone as $key => $val) {
                if (is_numeric($val)) {
                    $acceptthreeone[$key] = $val*1.0;
                } else {
                    $acceptthreeone[$key] = NULL;
                }
            }
            foreach ($acceptthreetwo as $key => $val) {
                if (is_numeric($val)) {
                    $acceptthreetwo[$key] = $val*1.0;
                } else {
                    $acceptthreetwo[$key] = NULL;
                }
            }
            foreach ($arrserialize['arrthree'] as $key => $val) {
                $arrserialize['arrthree'][$key][1] = $inputarrthree[$key];
                $arrserialize['arrthree'][$key][2] = empty($inputarrthree[$key]) ? '-' : ($inputarrthree[$key] - $val[0]);
                $arrserialize['arrthree'][$key][3] = $acceptthreeone[$key];
                $arrserialize['arrthree'][$key][4] = $acceptthreetwo[$key];
                $arrserialize['arrthree'][$key][5] = ($arrserialize['arrthree'][$key][2] == '-') ? '-' : ((abs($arrserialize['arrthree'][$key][2])>=$arrserialize['arrthree'][$key][3] && abs($arrserialize['arrthree'][$key][2])<=$arrserialize['arrthree'][$key][4]) ? 'Y' : 'N');
                $arrserialize['arrthree'][$key][6] = $hthreename[$key];
            }
            $data = array();
            $data['productCode'] = Application_Model_UserLogin::getInstance()->getUserCurrentProductCode();
            $data['date'] = $this->_request->getPost('startTime');
            $data['serializeData'] = serialize($arrserialize);
            $data['addTime'] = date('Y-m-d H:i:s');
//            $this->feedbackModel->delete(" `productCode`= '{$data['productCode']}' AND `date`='{$data['date']}' ");
//            $this->feedbackModel->insert($data);
            //加百分号的程序
            foreach ($arrserialize['arrone'] as $key => $val) {
                $arrserialize['arrone'][$key][3][0] = ($arrserialize['arrone'][$key][3][0] == '') ? '' : $arrserialize['arrone'][$key][3][0].'%';
                $arrserialize['arrone'][$key][3]['b3'] = ($arrserialize['arrone'][$key][3]['b3'] == '') ? '' : $arrserialize['arrone'][$key][3]['b3'].'%';
                $arrserialize['arrone'][$key][3]['gap3'] = ($arrserialize['arrone'][$key][3]['gap3'] == '') ? '' : $arrserialize['arrone'][$key][3]['gap3'].'%';
                $arrserialize['arrone'][$key][3]['acceptone3'] = ($arrserialize['arrone'][$key][3]['acceptone3'] == '') ? '' : $arrserialize['arrone'][$key][3]['acceptone3'].'%';
                $arrserialize['arrone'][$key][3]['accepttwo3'] = ($arrserialize['arrone'][$key][3]['accepttwo3'] == '') ? '' : $arrserialize['arrone'][$key][3]['accepttwo3'].'%';
                $arrserialize['arrone'][$key][4][0] = ($arrserialize['arrone'][$key][4][0] == '') ? '' : $arrserialize['arrone'][$key][4][0].'%';
                $arrserialize['arrone'][$key][4]['b4'] = ($arrserialize['arrone'][$key][4]['b4'] == '') ? '' : $arrserialize['arrone'][$key][4]['b4'].'%';
                $arrserialize['arrone'][$key][4]['gap4'] = ($arrserialize['arrone'][$key][4]['gap4'] == '') ? '' : $arrserialize['arrone'][$key][4]['gap4'].'%';
                $arrserialize['arrone'][$key][4]['acceptone4'] = ($arrserialize['arrone'][$key][4]['acceptone4'] == '') ? '' : $arrserialize['arrone'][$key][4]['acceptone4'].'%';
                $arrserialize['arrone'][$key][4]['accepttwo4'] = ($arrserialize['arrone'][$key][4]['accepttwo4'] == '') ? '' : $arrserialize['arrone'][$key][4]['accepttwo4'].'%';
            }
            $arrserialize['arrtwo'][0][0] = ($arrserialize['arrtwo'][0][0] == '') ? '' : $arrserialize['arrtwo'][0][0].'%';
            $arrserialize['arrtwo'][0][1] = ($arrserialize['arrtwo'][0][1] == '') ? '' : $arrserialize['arrtwo'][0][1].'%';
            $arrserialize['arrtwo'][0][3] = ($arrserialize['arrtwo'][0][3] == '') ? '' : $arrserialize['arrtwo'][0][3].'%';
            $arrserialize['arrtwo'][0][4] = ($arrserialize['arrtwo'][0][4] == '') ? '' : $arrserialize['arrtwo'][0][4].'%';
            
            $arrserialize['arrtwo'][2][0] = ($arrserialize['arrtwo'][2][0] == '') ? '' : $arrserialize['arrtwo'][2][0].'%';
            $arrserialize['arrtwo'][2][1] = ($arrserialize['arrtwo'][2][1] == '') ? '' : $arrserialize['arrtwo'][2][1].'%';
            $arrserialize['arrtwo'][2][3] = ($arrserialize['arrtwo'][2][3] == '') ? '' : $arrserialize['arrtwo'][2][3].'%';
            $arrserialize['arrtwo'][2][4] = ($arrserialize['arrtwo'][2][4] == '') ? '' : $arrserialize['arrtwo'][2][4].'%';
            
            $arrserialize['arrtwo'][7][0] = ($arrserialize['arrtwo'][7][0] == '') ? '' : $arrserialize['arrtwo'][7][0].'%';
            $arrserialize['arrtwo'][7][1] = ($arrserialize['arrtwo'][7][1] == '') ? '' : $arrserialize['arrtwo'][7][1].'%';
            $arrserialize['arrtwo'][7][3] = ($arrserialize['arrtwo'][7][3] == '') ? '' : $arrserialize['arrtwo'][7][3].'%';
            $arrserialize['arrtwo'][7][4] = ($arrserialize['arrtwo'][7][4] == '') ? '' : $arrserialize['arrtwo'][7][4].'%';
            
            
                        
            $arrserialize['arrthree'][6][0] = ($arrserialize['arrthree'][6][0] == '') ? '' : $arrserialize['arrthree'][6][0].'%';
            $arrserialize['arrthree'][6][1] = ($arrserialize['arrthree'][6][1] == '') ? '' : $arrserialize['arrthree'][6][1].'%';
            $arrserialize['arrthree'][6][3] = ($arrserialize['arrthree'][6][3] == '') ? '' : $arrserialize['arrthree'][6][3].'%';
            $arrserialize['arrthree'][6][4] = ($arrserialize['arrthree'][6][4] == '') ? '' : $arrserialize['arrthree'][6][4].'%';
            
            $arrserialize['arrthree'][8][0] = ($arrserialize['arrthree'][8][0] == '') ? '' : $arrserialize['arrthree'][8][0].'%';
            $arrserialize['arrthree'][8][1] = ($arrserialize['arrthree'][8][1] == '') ? '' : $arrserialize['arrthree'][8][1].'%';
            $arrserialize['arrthree'][8][3] = ($arrserialize['arrthree'][8][3] == '') ? '' : $arrserialize['arrthree'][8][3].'%';
            $arrserialize['arrthree'][8][4] = ($arrserialize['arrthree'][8][4] == '') ? '' : $arrserialize['arrthree'][8][4].'%';
            //写入EXCEL文件
            $prodcutname = $this->partnerProductModel->getProductNameByProductCode($data['productCode']);
            $objPHPExcel = new PHPExcel_PHPExcel();
            $objPHPExcel->getProperties()->setCreator("Yek BI System")
                        ->setLastModifiedBy("Yek BI")
                        ->setTitle("{$data['date']}-运营日报解析反馈表-{$prodcutname}")
                        ->setSubject("{$data['date']}-运营日报解析反馈表-{$prodcutname}")
                        ->setDescription("")
                        ->setKeywords("")
                        ->setCategory("");
            $objPHPExcel->getActiveSheet()->mergeCells('A1:I1');
            $objPHPExcel->getActiveSheet()->setCellValue('A1', '运营日报情况反馈');
            $keyArr = array('A2'=>'','B2'=>'项目名称','C2'=>'耶客数据','D2'=>'商家数据','E2'=>$prodcutname,'F2'=>'日报对应日期','G2'=>$data['date'],'H2'=>'撰写人','I2'=>'',
                            'A3'=>'分析角度','B3'=>'分析项目','C3'=>'数据库提取','D3'=>'运营经理填写','E3'=>'平均数值落差','F3'=>'上下可接受浮动区间','G3'=>'是否正常','H3'=>'不正常情况说明','I3'=>'希望获取的进一步跟进说明'
                            );
            foreach ($keyArr as $key => $val) {
                $objPHPExcel->getActiveSheet()->setCellValue($key, $val);
            }
    
            $rowsnum = 3;
            foreach ($arrserialize['arrone'] as $key => $val) {
                foreach ($val as $k => $v) {
                    $rowsnum++;
                }
            }
            $objPHPExcel->getActiveSheet()->getStyle('C')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);  
            $objPHPExcel->getActiveSheet()->getStyle('C')->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER); 
            $objPHPExcel->getActiveSheet()->getStyle('D')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);  
            $objPHPExcel->getActiveSheet()->getStyle('D')->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER); 
            $objPHPExcel->getActiveSheet()->getStyle('E')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);  
            $objPHPExcel->getActiveSheet()->getStyle('E')->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER); 
            
            //第一大行
            $objPHPExcel->getActiveSheet()->mergeCells('A4:A'.$rowsnum);
            $objPHPExcel->getActiveSheet()->setCellValue('A4', '客户统计与耶客统计是否有误差');
            $i = 0;
            foreach ($arrserialize['arrone'] as $key => $val) {
                foreach ($val as $k => $v) {
                    $objPHPExcel->getActiveSheet()->setCellValue("B".($i+4), $key.$v["name".$k]);
                    $objPHPExcel->getActiveSheet()->setCellValue("C".($i+4), $val[$k][0]);
                    $objPHPExcel->getActiveSheet()->setCellValue("D".($i+4), $v["b".$k]);
                    $objPHPExcel->getActiveSheet()->setCellValue("E".($i+4), $v["gap".$k]);
                    $objPHPExcel->getActiveSheet()->setCellValue("F".($i+4), $v["acceptone".$k].'-'.$v["accepttwo".$k]);
                    $objPHPExcel->getActiveSheet()->setCellValue("G".($i+4), $v["is".$k]);
                    $i++;
                }
            }
            //第二大行
            $objPHPExcel->getActiveSheet()->mergeCells('A'.($rowsnum+1).':A'.($rowsnum+8));
            $objPHPExcel->getActiveSheet()->setCellValue('A'.($rowsnum+1), '运营日报当天数据与近日同比数据比较');
            $i = $rowsnum+1;
            foreach ($arrserialize['arrtwo'] as $val) {
                $objPHPExcel->getActiveSheet()->setCellValue("B".($i), $val[6]);
                $objPHPExcel->getActiveSheet()->setCellValue("C".($i), $val[0]);
                $objPHPExcel->getActiveSheet()->setCellValue("D".($i), $val[1]);
                $objPHPExcel->getActiveSheet()->setCellValue("E".($i), $val[2]);
                $objPHPExcel->getActiveSheet()->setCellValue("F".($i), $val[3].'-'.$val[4]);
                $objPHPExcel->getActiveSheet()->setCellValue("G".($i), $val[5]);
                $i++;
            }
            //第三大行
            $objPHPExcel->getActiveSheet()->mergeCells('A'.$i.':A'.($i+8));
            $objPHPExcel->getActiveSheet()->setCellValue('A'.$i, '推广数据与近日同比数据比对');
            $i;
            foreach ($arrserialize['arrthree'] as $val) {
                $objPHPExcel->getActiveSheet()->setCellValue("B".($i), $val[6]);
                $objPHPExcel->getActiveSheet()->setCellValue("C".($i), $val[0]);
                $objPHPExcel->getActiveSheet()->setCellValue("D".($i), $val[1]);
                $objPHPExcel->getActiveSheet()->setCellValue("E".($i), $val[2]);
                $objPHPExcel->getActiveSheet()->setCellValue("F".($i), $val[3].'-'.$val[4]);
                $objPHPExcel->getActiveSheet()->setCellValue("G".($i), $val[5]);
                $i++;
            }

            $keyArr = array('A' . $i => '备注总结：',
                            'A' . ($i+1) => '表现较好的推广渠道',
                            'A' . ($i+2) => '表现较差的推广渠道'
                            );
            foreach ($keyArr as $key => $val) {
                $objPHPExcel->getActiveSheet()->mergeCells('B' .$i. ':I' . $i);
                $objPHPExcel->getActiveSheet()->setCellValue($key, $val);
                $i++;
            }
            $fileName = $data['date'].'_'.iconv('UTF-8','GBK//IGNORE',$prodcutname);
            $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
            $outputFileName = $fileName.".xls";
            //到浏览器  
            header("Content-Type: application/force-download");  
            header("Content-Type: application/octet-stream");  
            header("Content-Type: application/download");  
            header('Content-Disposition:inline;filename="'.$outputFileName.'"');  
            header("Content-Transfer-Encoding: binary");  
            header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");  
            header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");  
            header("Cache-Control: must-revalidate, post-check=0, pre-check=0");  
            header("Pragma: no-cache");
            $objWriter->save('php://output');
        }
        exit;
    }
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
}